﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<!-- source http://www.scnoob.com More templates http://www.scnoob.com/moban -->
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>下级订单</title>

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/bootstrap.min.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/fonts/line-icons.css}">

    <link th:href="@{/assets/plugins/datatables/dataTables.bootstrap4.min.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/assets/plugins/datatables/buttons.bootstrap4.min.css}" rel="stylesheet" type="text/css"/>

    <link th:href="@{/assets/plugins/datatables/responsive.bootstrap4.min.css}" rel="stylesheet" type="text/css"/>

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/main.css}">

    <link rel="stylesheet" type="text/css" th:href="@{/assets/css/responsive.css}">
</head>
<body>
<div class="app header-default side-nav-dark">
    <div class="layout">

        <div class="page-container pl-0">
            <div class="main-content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <div class="card-header border-bottom">
                                    <h4 class="card-title">下级订单列表</h4>
<!--                                    <div style="color: red" id="tips"></div>-->
                                </div>
                                <div type="text" style="display: none" id="userId"
                                     th:text="${session.userEntity.id}"></div>
                                <div class="card-body">
                                    <div class="table-responsive">
                                        <table id="datatable" class="table table-bordered" style="width: 100%">
                                            <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>商品名称</th>
<!--                                                <th>购买数量</th>-->
                                                <th>用户付款金额</th>
                                                <th>用户支付状态</th>
                                                <th>商家收款金额</th>
                                                <th>我的转账状态</th>
<!--                                                <th>我的利润</th>-->
                                                <!--                        <th>订单状态</th>-->
                                                <th>确认用户支付</th>
                                                <th>付款给商家</th>
                                                <th>操作</th>
                                            </tr>

                                            </thead>
                                            <!--                      <tbody>-->
                                            <!--                      <tr th:each="order:${orders}">-->
                                            <!--                        <td th:text="${order.id}"></td>-->
                                            <!--                        <td th:text="${order.productEntityName}"></td>-->
                                            <!--                        <td th:text="${order.totalNum}"></td>-->
                                            <!--                        <td th:text="${order.payMoney}"></td>-->
                                            <!--                        <td th:switch="${order.payStatus}" class="text-center">-->
                                            <!--                          <span th:case="'0'">已支付</span>-->
                                            <!--                          <span th:case="'1'">支付未被确认</span>-->
                                            <!--                          <span th:case="'2'">未支付</span>-->
                                            <!--                        </td>-->

                                            <!--                        <td th:text="${order.referPayMoney}"></td>-->
                                            <!--                        <td th:switch="${order.referPayStatus}" class="text-center">-->
                                            <!--                          <span th:case="'0'">已支付</span>-->
                                            <!--                          <span th:case="'1'">支付未被确认</span>-->
                                            <!--                          <span th:case="'2'">未支付</span>-->
                                            <!--                        </td>-->
                                            <!--                        <td th:text="${order.welfareMoney}"></td>-->
                                            <!--                        <td th:switch="${order.orderStatus}" class="text-center">-->
                                            <!--                          <span th:case="'0'">已完成</span>-->
                                            <!--                          <span th:case="'1'">未完成</span>-->
                                            <!--                        </td>-->
                                            <!--                        <td th:switch="${order.payStatus}" class="text-center">-->
                                            <!--                          <a th:case="'0'">已支付</a>-->
                                            <!--                          <a th:case="'1'">-->
                                            <!--                            <button type="button" class="btn btn-outline-success" data-toggle="modal" data-target="#myModal">确认用户支付</button></a>-->
                                            <!--                          <a th:case="'2'">未支付</a>-->

                                            <!--                          &lt;!&ndash; 模态框（Modal） &ndash;&gt;-->
                                            <!--                          <div style="margin-top: 260px" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">-->
                                            <!--                            <div class="modal-dialog">-->
                                            <!--                              <div class="modal-content">-->
                                            <!--                                <div class="modal-header">-->
                                            <!--                                  <h4 class="modal-title" id="myModalLabel">确认用户已支付</h4>-->
                                            <!--                                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>-->
                                            <!--                                </div>-->
                                            <!--                                <div class="modal-body">确认用户已支付</div>-->
                                            <!--                                <div class="modal-footer">-->
                                            <!--                                  <button type="button" class="btn btn-default" data-dismiss="modal">返回</button>-->
                                            <!--                                  <button type="button" class="btn btn-primary" th:onclick="|orderConfirmUserPay(${order.id})|">确认</button>-->
                                            <!--                                </div>-->
                                            <!--                              </div>&lt;!&ndash; /.modal-content &ndash;&gt;-->
                                            <!--                            </div>&lt;!&ndash; /.modal &ndash;&gt;-->
                                            <!--                          </div>-->

                                            <!--                        </td>-->
                                            <!--                        <td th:switch="${order.referPayStatus}" class="text-center">-->
                                            <!--                          <a th:case="'0'">已支付</a>-->
                                            <!--                          <a th:case="'2'" th:href="@{findMerchantEntityAccout(orderId=${order.id},productId=${order.productId})}">-->
                                            <!--                            <button type="button" class="btn btn-danger btn-rounded"-->
                                            <!--                                    style="padding: 10px 15px;">-->
                                            <!--                              <span>去支付</span>-->
                                            <!--                            </button>-->
                                            <!--                          </a>-->
                                            <!--                          <a th:case="'1'">支付未被确认</a>-->
                                            <!--                        </td>-->
                                            <!--                      </tr>-->
                                            <!--                      </tbody>-->
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="preloader">
    <div class="loader" id="loader-1"></div>
</div>

<script th:src="@{/assets/js/jquery-min.js}"></script>
<script th:src="@{/assets/js/popper.min.js}"></script>
<script th:src="@{/assets/js/bootstrap.min.js}"></script>
<script th:src="@{/assets/js/jquery.app.js}"></script>
<script th:src="@{/assets/js/main.js}"></script>

<script th:src="@{/assets/plugins/datatables/jquery.dataTables.min.js}"></script>
<script th:src="@{/assets/plugins/datatables/dataTables.bootstrap4.min.js}"></script>

<script th:src="@{/assets/plugins/datatables/dataTables.buttons.min.js}"></script>
<script th:src="@{/assets/plugins/datatables/buttons.bootstrap4.min.js}"></script>
<script th:src="@{/assets/plugins/datatables/jszip.min.js}"></script>
<script th:src="@{/assets/plugins/datatables/pdfmake.min.js}"></script>
<script th:src="@{/assets/plugins/datatables/vfs_fonts.js}"></script>
<script th:src="@{/assets/plugins/datatables/buttons.html5.min.js}"></script>
<script th:src="@{/assets/plugins/datatables/buttons.print.min.js}"></script>
<script th:src="@{/assets/plugins/datatables/buttons.colVis.min.js}"></script>

<script th:src="@{/assets/plugins/datatables/dataTables.responsive.min.js}"></script>
<script th:src="@{/assets/plugins/datatables/responsive.bootstrap4.min.js}"></script>

<script th:src="@{/assets/js/datatables.init.js}"></script>
</body>
<script type="text/javascript" th:inline="none">
    $("#datatable").DataTable({
        "oLanguage": {
            "sUrl": "/assets/page_zh_CN.json"
        },
        ordering:true,
        "order": [[ 0, "desc" ]],
        serverSide: true, //开启后端模式
        // searching: false,  //禁用原生搜索
        // "pageLength": 10,         //初始化显示几条数据
        "sAjaxSource": "/admin/order/pageTable",
        "fnServerData": function (sSource, aoData, fnCallback) {
            $.ajax({
                "dataType": 'json',
                "type": "POST",
                "url": sSource,
                "data": {
                    aoData: JSON.stringify(aoData)
                },
                "success": fnCallback
            });
        },
        "bDeferRender": true,// 是否启用延迟加载：当你使用AJAX数据源时，可以提升速度。默认值：False
        //列表表头字段
        "aoColumns": [
            {"mData": "id", "width": "5%", "orderable": false},
            {"mData": "productName", "width": "10%", "orderable": false},
            // {"mData": "totalNum", "width": "10%", "orderable": false},
            {"mData": "payMoney", "width": "13%", "orderable": false},
            {"mData": "payStatus", "width": "13%", "orderable": false},

            {"mData": "referPayMoney", "width": "13%", "orderable": false},
            {"mData": "referPayStatus", "width": "13%", "orderable": false},
            // {"mData": "welfareMoney", "width": "10%", "orderable": false},
            {"mData": "confirm", "width": "13%", "orderable": false},
            {"mData": "operate","width": "10%", "orderable": false},
            {"mData": "details","width": "10%", "orderable": false}
        ],
        "fnRowCallback": function (nRow, aData, iDisplayIndex) {//相当于对字段格式化
            // 订单详情
            var html1 = "";
            html1+='<a href="/admin/order/referFindById?id='+aData["details"]+'">详情</a>';
            $('td:eq(8)', nRow).html(html1);

            // 用户支付状态
            if (aData["payStatus"] == 0) {
                $('td:eq(3)', nRow).html("<span>已支付</span>");
            } else if (aData["payStatus"] == 1) {
                $('td:eq(3)', nRow).html("<span>支付未被确认</span>");
            } else if (aData["payStatus"] == 2) {
                $('td:eq(3)', nRow).html("<span>未支付</span>");
            }

            // 商户支付状态
            if (aData["referPayStatus"] == 0) {
                $('td:eq(5)', nRow).html("<span>已支付</span>");
            } else if (aData["referPayStatus"] == 1) {
                $('td:eq(5)', nRow).html("<span>支付未被确认</span>");
            } else if (aData["referPayStatus"] == 2) {
                $('td:eq(5)', nRow).html("<span>未支付</span>");
            }

            var html = "";
            // 确认用户支付
            if (aData["confirm"] == 0) {
                html += '<a>已支付</a>';
            } else if (aData["confirm"] == 1) {
                html += '<a>' +
                    '<button type="button" class="btn btn-outline-success" data-toggle="modal" data-target="#'+aData["id"]+'">确认支付</button>' +
                    '</a>' +
                    '<!-- 模态框（Modal） -->\n' +
                    '<div style="margin-top: 260px" class="modal fade" id="'+aData["id"]+'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">\n' +
                    '<div class="modal-dialog">\n' +
                    '<div class="modal-content">\n' +
                    '<div class="modal-header">\n' +
                    '<h4 class="modal-title" id="myModalLabel">确认用户已支付</h4>\n' +
                    '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\n' +
                    '</div>\n' +
                    '<div class="modal-body">确认用户已支付</div>\n' +
                    '<div class="modal-footer">\n' +
                    '<button type="button" class="btn btn-default" data-dismiss="modal">返回</button>\n' +
                    '<button type="button" class="btn btn-primary" onclick="orderConfirmUserPay(' + aData["id"] + ')">确认</button>\n' +
                    '</div>\n' +
                    '</div><!-- /.modal-content -->\n' +
                    '</div><!-- /.modal -->\n' +
                    '</div>';
            } else if (aData["confirm"] == 2) {
                html += '<a>未支付</a>';
            }
            $('td:eq(6)', nRow).html(html);

            // 转账给商家
            html = "";
            if (aData["operate"] == 0) {
                html += '<a>已支付</a>';
            } else if (aData["operate"] == 2 && aData["payStatus"] == 0) {
                html += '<a href="/admin/order/findMerchantEntityAccout?orderId=' + aData["id"] + '&productId=' + aData["productId"] + '">\n' +
                    '<button type="button" class="btn btn-outline-danger" style="padding: 10px 15px;">\n' +
                    '<span>去支付</span>\n' +
                    '</button>\n' +
                    '</a>';
            } else if (aData["operate"] == 2 && aData["payStatus"] != 0) {
                html += '<a>用户支付未完成</a>';
            } else if (aData["operate"] == 1) {
                html += '<a>支付未被确认</a>';
            }
            $('td:eq(7)', nRow).html(html);
        }
    });
    // $(function () {
    //     $("#tips").hide();
    // });

    function orderConfirmUserPay(orderId) {
        // alert(orderId);
        var userId = $("#userId").text();
        console.log(orderId);
        console.log(userId);
        $.post("orderConfirmUserPay",
            {"id": orderId},
            function (data) {
                if (data != "0") {
                    window.open("/admin/order/getAllByReferId?referId=" + userId, "_self");
                } else {
                    $("#tips").text("确认支付失败");
                    $("#tips").show();
                }
            }
        )
    }

</script>


<!-- source http://www.scnoob.com More templates http://www.scnoob.com/moban -->
</html>


